﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<?php
		$output = isset($_POST['output']) ? $_POST['output'] : $_GET['output'];
		$customer_id = isset($_POST['customer_id']) ? $_POST['customer_id'] : $_GET['customer_id'];
		if($output=="mark") print "<title>Mark point on map report</title>";
		else print "<title>View Map Report</title>";
?>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAYRo9VK60DzqRHsBkppaFlRS_eW2k_STNLchqXsLMWCvAXNHBZRT_b4mM5Ff4mjtkoKAiF91eUDVAvg" type="text/javascript"></script>
<script src="getValue.js" type="text/javascript"></script>
<script src="common.js" type="text/javascript"></script>

    <style type="text/css">
      
      body {
        font-family: Verdana, Arial, sans serif;
        font-size: 11px;
        margin: 2px;
      }
	  .font1{
		font-family: Tahoma,Verdana, Arial, sans serif;
        font-size: 12px;
	  }
      table.directions th {
		background-color:#FFCC00;
      }
      img {
        color: #000000;
      }
	 DIV.body
		{
			BORDER-RIGHT: #808080 2px solid;
			PADDING-RIGHT: 1px;
			BORDER-TOP: #808080 2px solid;
			PADDING-LEFT: 1px;
			PADDING-BOTTOM: 1px;
			BORDER-LEFT: #808080 2px solid;
			COLOR: #000000;
			PADDING-TOP: 1px;
			BORDER-BOTTOM: #808080 2px solid;
			font-family: Tahoma, Verdana, Arial, sans serif, Tahoma;
			font-size: 12px;
			margin: 2px;
			HEIGHT: 80px;
			BACKGROUND-COLOR: #ffffff;
			TEXT-DECORATION: none
		}

    </style>
<?php
		if($output=="mark"){
?>
		<script type="text/javascript">
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		var lat=getVar("lat");
		var lng=getVar("lon");
		var point = new GLatLng(lat,lng);
		var string_lat = point.lat();
		var string_lng = point.lng();
        map.setCenter(point, 13);
	
		var window_html = '<form name="formmain" method="get" action="viewmap.php"><table width="300" cellpadding="0" cellspacing="0"><tr><td align="left" width="90"><font class="font1"><b>Location code : </b></font><br><input type="text" name="locatecode" value="MR-" style="background:none;"></td><td align="left" width="90"><font class="font1"><b>Location name : </b></font><br><input type="text" name="locatename" value="MarkR" style="background:none;"></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="left" width="90"><font class="font1"><b>Latitude : </b></font><br><input type="text" name="lat" value="'+string_lat+'" style="background:none;" readonly></td><td align="left" width="90"><font class="font1"><b>Longitude : </b></font><br><input type="text" name="lng" value="'+string_lng+'" style="background:none;" readonly></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="left" width="90"><font class="font1"><b>Location color : </b></font><br><input type="text" name="codecolor" value="" style="background:none;" readonly></td><td align="left" width="90"><font class="font1"><b>Redius [Metre(s)] : </b></font><br><input type="text" name="redius" value="" style="background:none;" readonly></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="center" colspan="2"><input type="submit" name="btmenu" value="Save">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="btmenu" value="Cancel"></td></tr></table></form>';
		//map.addOverlay(point);
		
		/*var marker = new GMarker(point);
		map.addOverlay(marker);
		
        GEvent.addListener(marker, "moveend", function() {
			//var pointtest = marker.getPoint();
			//var marker1 = new GMarker(pointtest);
			//map.addOverlay(marker1);
		  //var point1=map.getInfoWindow();
		  //var center=map.getPoint();
          var center = marker.getPoint();
          document.getElementById("message").innerHTML = center.toString();{ draggable: true }; icon: mark_icon 
        });*/
		// var mark_icon = new GIcon(G_DEFAULT_ICON);
		// mark_icon.image = './icon/icon-dd-play-trans.png';
		 //marker_icon = { icon:mark_icon };
		 
		 var marker = new GMarker(point, { draggable: true });
		 //var icon_marker = marker.getIcon();
		 //var mark_icon = new GIcon(icon_marker);

		 //var lng_lat= marker1.getPoint();
		 //var marker = new GMarker(lng_lat, marker_icon);
		 //var marker = new GMarker(point);

        GEvent.addListener(marker, "dragstart", function() {
          map.closeInfoWindow();
        });

        GEvent.addListener(marker, "dragend", function() {
		  var lat_lng = marker.getPoint();
		  var string_lat = lat_lng.lat();
		  var string_lng = lat_lng.lng();
		  //var window_html = '<div style="width: 300px; padding-right: 10px"><b>Lat/Lng </b>'+string_lat+', '+string_lng+'<\/div>';
		  var window_html = '<form name="formmain" method="get" action="viewmap.php"><table width="300" cellpadding="0" cellspacing="0"><tr><td align="left" width="90"><font class="font1"><b>Location code : </b></font><br><input type="text" name="locatecode" value="MR-" style="background:none;"></td><td align="left" width="90"><font class="font1"><b>Location name : </b></font><br><input type="text" name="locatename" value="MarkR" style="background:none;"></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="left" width="90"><font class="font1"><b>Latitude : </b></font><br><input type="text" name="lat" value="'+string_lat+'" style="background:none;" readonly></td><td align="left" width="90"><font class="font1"><b>Longitude : </b></font><br><input type="text" name="lng" value="'+string_lng+'" style="background:none;" readonly></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="center" colspan="2"><input type="submit" name="btmenu" value="Save">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="btmenu" value="Cancel"></td></tr></table></form>';
          marker.openInfoWindowHtml(window_html);
        });

		 GEvent.addListener(marker, "click", function() {
		  var lat_lng = marker.getPoint();
		  //var string_lat_lng = lat_lng.toString();
		  var string_lat = lat_lng.lat();
		  var string_lng = lat_lng.lng();
		  //var window_html = '<div style="width: 300px; padding-right: 10px"><b>Lat/Lng </b>'+string_lat+', '+string_lng+'<\/div>';
		  var window_html = '<form name="formmain" method="get" action="viewmap.php"><table width="300" cellpadding="0" cellspacing="0"><tr><td align="left" width="90"><font class="font1"><b>Location code : </b></font><br><input type="text" name="locatecode" value="MR-" style="background:none;"></td><td align="left" width="90"><font class="font1"><b>Location name : </b></font><br><input type="text" name="locatename" value="MarkR" style="background:none;"></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="left" width="90"><font class="font1"><b>Latitude : </b></font><br><input type="text" name="lat" value="'+string_lat+'" style="background:none;" readonly></td><td align="left" width="90"><font class="font1"><b>Longitude : </b></font><br><input type="text" name="lng" value="'+string_lng+'" style="background:none;" readonly></td></tr><tr><td colspan="2">&nbsp;</td></tr><tr><td align="center" colspan="2"><input type="submit" name="btmenu" value="Save">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="btmenu" value="Cancel"></td></tr></table></form>';
          marker.openInfoWindowHtml(window_html);
        });

        map.addOverlay(marker);
        marker.openInfoWindowHtml(window_html);

      }
    }  
    </script>
<?php
		}else{
			$btmenu = isset($_POST['btmenu']) ? $_POST['btmenu'] : $_GET['btmenu'];
			/*if($btmenu=="Save"){
				$table="locations";
				$dbflive="host=172.30.13.3 port=5423 dbname=fleetlive user=postgres password=";
				$dbconn_flive=pg_connect($dbflive);
				//$sql="";
				$sql_insert="insert into ".$table." (location_code, location_name, customer_id, location_description, location_radius, location_type) values ('','',".$customer_id.",)";
				$result=@pg_query($dbconn_flive, $sql_insert);
				pg_free_result($result);
				pg_close($dbconn_flive);
			}*/
?>
    <script type="text/javascript">
    //<![CDATA[

    var map;
	//var box_code = getVar("box_code");
	var plate = decode(getVar("plate"),"utf8");
	var locate = decode(getVar("locate"),"utf8");//"";//
	var platename = decode(getVar("plate_name"),"utf8");
	var v_status = decode(getVar("vehicle_status"),"utf8");
	var start_time = decode(getVar("start_time"),"utf8");
	var stop_time = decode(getVar("stop_time"),"utf8");
	var difftime = decode(getVar("timediff"),"utf8");
	var lang = getVar("lang");

	//var MyDate = new Date(start_time);
	//alert(MyDate.getTime());
	//var key_menu = getVar("keymenu");
	//var nameplate = decode(getVar("nameplate"),"utf8");
	//var namelocate = decode(getVar("namelocate"),"utf8");

	if(lang=="th"){
		var WINDOW_HTML = '<div style="width: 320px; padding-right: 5px"><b>ทะเบียนรถ </b>'+plate+' <b>ชื่อเรียกรถ  </b>'+platename+'<br><b>สถานที่ </b> '+locate+'<br><b>สถานะ </b>'+v_status+'<br><b>วัน/เวลา</b> '+start_time+' - '+stop_time+' <b>ระยะเวลา</b> '+difftime+'<\/div>';
	}else{
		var WINDOW_HTML = '<div style="width: 320px; padding-right: 5px"><b>Plate No </b>'+plate+' <b>Vehicle </b>'+platename+'<br><b>Location </b>'+locate+'<br><b>Status </b>'+v_status+'<br><b>Date/Time</b> '+start_time+' - '+stop_time+' <b>Duration</b> '+difftime+'<\/div>';
	}

    function load() {
      if (GBrowserIsCompatible()) {      
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		// Create our "tiny" marker icon
		var lat=getVar("lat");
		var lng=getVar("lon");
		var point = new GLatLng(lat,lng);
		map.setCenter(point,13);
		var marker = new GMarker(point);
       map.addOverlay(marker);
       GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(WINDOW_HTML);
      });
       marker.openInfoWindowHtml(WINDOW_HTML);
		//var icon = new GIcon();
		//icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		//icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		//icon.iconSize = new GSize(12, 20);
		//icon.shadowSize = new GSize(22, 20);
		//icon.iconAnchor = new GPoint(6, 20);
		//icon.infoWindowAnchor = new GPoint(5, 1);
		//var lat=getVar("lat");
		//var lng=getVar("lon");
		//var point = new GLatLng(lat,lng);
		//map.setCenter(point,13);
		//map.addOverlay(new GMarker(point, icon));
      }
    }
    
    //]]>
    </script>
<?php
	}
?>
  </head>

  <body onload="load()" onunload="GUnload()">
<?php
	
		/*$lat = isset($_POST['lat']) ? $_POST['lat'] : $_GET['lat'];
		$lon = isset($_POST['lon']) ? $_POST['lon'] : $_GET['lon'];
		$plate = isset($_POST['plate']) ? $_POST['plate'] : $_GET['plate'];
		$location = isset($_POST['locate']) ? $_POST['locate'] : $_GET['locate'];
		$platename = isset($_POST['plate_name']) ? $_POST['plate_name'] : $_GET['plate_name'];
		$output = isset($_POST['output']) ? $_POST['output'] : $_GET['output'];*/

		$lang_check = isset($_POST['lang']) ? $_POST['lang'] : $_GET['lang'];
		if($lang_check=="th"){
			//echo"<h2>".iconv("TIS-620","UTF-8","แสดงแผนที่")."</h2>";
			echo"<h2>แสดงแผนที่</h2>";
		}else{
			echo"<h2>View Map</h2>";
		}

		/*if($output=="map"){
			echo "<form name=\"formexport\" action=\"pdfmap.php\" method=\"get\" target=\"_blank\">";
			echo "<input type=\"hidden\" name=\"lat\" value=\"".$lat."\">";
			echo "<input type=\"hidden\" name=\"lon\" value=\"".$lon."\">";
			echo "<input type=\"hidden\" name=\"plate\" value=\"".urlencode($plate)."\">";
			echo "<input type=\"hidden\" name=\"platename\" value=\"".urlencode($platename)."\">";
			echo "<input type=\"hidden\" name=\"location\" value=\"".urlencode($location)."\">";
			echo "<input type=\"submit\" name=\"btmenu\" value=\"Export PDF\">";
			echo"</form>";
		}*/
?>
    <br/>
 <table class="directions">

    <tr>
<?php
	if($lang_check=="th"){
		echo"<th align=\"left\">แผนที่</th>";
	}else{
		echo"<th align=\"left\">Map</th>";
	}
?>
	</tr>
    <tr>
    <td valign="top"><div id="map" class="body" style="width: 500px; height: 470px"></div></td>
    </tr>
    </table>    
	
    
  </body>

</html>


